{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os##引入OS库\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "excels = [pd.read_excel(fname) for fname in os.listdir('./') if 'xls' in fname]\n",
    "##Excel文件有两种后缀：xls和xlsx，都包含了xls，故通过文件名中是否有xls，来判断该文件是否为Excel文件。\n",
    "##还有一点就是注意文件路径，我代码和Excel文件在同一目录下，所以是‘./’\n",
    "##\n",
    "df01 = pd.concat(excels)##简单合并\n",
    "df01.to_excel('汇总.xlsx', index=False)##若index为True，则每行数据最前面会多出一个索引值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
